﻿Imports System.Data
Imports ADOEntityETL
Imports ADOEntity

Partial Class frmChkRiskDetail
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strdeptCode As String
        Dim strBranchCode As String 

        If Not (IsPostBack) Then
            hdfVar1.Value = Request.Item("deptCode")
            hdfVar2.Value = Request.Item("BranchCode") 

            strdeptCode = Request.Item("deptCode")
            strBranchCode = Request.Item("BranchCode") 

        Else
            If Not (IsCallback) Then
                strdeptCode = convertStringEncode(hdfVar1.Value)
                strBranchCode = convertStringEncode(hdfVar2.Value) 
            Else
                strdeptCode = hdfVar1.Value
                strBranchCode = hdfVar2.Value 
            End If

        End If
        dailyEtl(strdeptCode, strBranchCode)

    End Sub

    Private Function convertStringEncode(ByVal strCon As String) As String
        Dim rtStr As String = ""
        Try

            rtStr = Encoding.UTF8.GetString(Encoding.GetEncoding("tis-620").GetBytes(strCon))
        Catch ex As Exception
            Throw ex
        End Try
        Return rtStr
    End Function



    Private Sub dailyEtl(ByVal strDeptCode As String, ByVal strBranchCode As String )


        Dim clsVarParameter As clsVariable
        Dim clsSessionMenuRight As New clsSessionMenuRight
        Dim clsFormatDate As New clsDateFormat
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""
        Dim strSql As String = ""
        Dim arrDepCode As String() = Nothing
        Dim arrBranchCode As String() = Nothing
        Dim arrStatus As String() = Nothing


        Dim ds As New dsKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptChkRiskAllCustomer = New rptChkRiskAllCustomer

        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}ds.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)


                re.prmDep.Value = arrDepCode(0) & " : " & arrDepCode(1)
            Else
                re.prmDep.Value = " - "
            End If
        End If

        If Not strBranchCode = "" Then
            arrBranchCode = strBranchCode.Split("/")
            If Not arrBranchCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}ds.BRANCHCODE = :BRANCHCODE", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                          .valueColumn = arrBranchCode(0)}
                colVarParameter.Add(clsVarParameter)

                re.prmBranch.Value = arrBranchCode(0) & " : " & arrBranchCode(1)
            Else
                re.prmBranch.Value = " - "

            End If
        End If

          

        strSql = "select  ds.DEPTCODE, ds.BRANCHCODE, ds.BRANCHNAME, ds.RISK0, ds.RISK1, ds.RISK2, ds.RISK3, ds.TOTAL " _
                & " from " & System.Configuration.ConfigurationSettings.AppSettings("TableV_RISKTOTAL") & "  ds   " _
                & StrWhere _
                & " order by ds.BRANCHCODE  "


        cls.rptChkRiskDetail(re, strSql, ds, colVarParameter)
        ' re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re

    End Sub

    'Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
    '    Session("ds") = ds
    'End Sub
End Class
